package com.segment.mybatis;

import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SqlSessionFactoryManager {
	private static final SqlSessionFactory sqlSessionFactory;
	
	static{
		try{
			String resource = "com/segment/mybatis/mybatis-config.xml";
			Reader reader = Resources.getResourceAsReader(resource);
			sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader,"ranking");
		}catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
	}
	
	public SqlSessionFactoryManager(){}
	
	public static SqlSessionFactory getSqlMapper(){
		
		return sqlSessionFactory;
	}
}
